import {createRouter, createWebHashHistory, createWebHistory} from "vue-router";
import layout from "../layout/index.vue";
import loginVue from "../views/login/index.vue";
import home from "../views/home/index.vue"
import {menuRecord} from "../store/menu.js"


const routes = [
  {
    path: "/login",
    name: "login",
    component: loginVue,
  },
  {
    path: "/",
    component: layout,
    redirect: "index",
    name: "首页",
    meta: {
      id: "1",
      show: false,
      icon: "/menu/1.png"
    },
    children: [
      {
        path: "index",
        name: "控制台",
        component: home,
        meta: {
          parentId: "1",
          id: "1-1",
          show: false,
        },
      },
    ],
  },
  {
    path: "/user",
    name: "用户管理",
    component: layout,
    meta: {
      id: "2",
      show: false,
      icon: "/menu/2.png"
    },
    children: [
      {
        path: "index",
        name: "用户管理",
        component: () => import("@/views/user/index.vue"),
        meta: {
          parentId: "2",
          id: "2-1",
          show: false,
        },
      },
    ]
  },
  {
    path: "/audit",
    name: "审核中心",
    component: layout,
    meta: {
      id: "3",
      show: false,
      icon: "/menu/3.png"
    },
    children: [
      {
        path: "entryApplication",
        name: "入职申请",
        component: () => import("@/views/auditCenter/entryApplication/index.vue"),
        meta: {
          parentId: "3",
          id: "3-1",
          show: false,
        },
      },
      {
        path: "resignationApplication",
        name: "离职申请",
        component: () => import("@/views/auditCenter/resignationApplication/index.vue"),
        meta: {
          parentId: "3",
          id: "3-2",
          show: false,
        },
      },
      {
        path: "notApply",
        name: "不在职申请",
        component: () => import("@/views/auditCenter/notApply/index.vue"),
        meta: {
          parentId: "3",
          id: "3-3",
          show: false,
        },
      },
    ]
  }
];


const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from) => {
  // if (!sessionStorage.getItem("KLogin") && to.path !== "/login") {
  //   return {name: 'login'}
  // }
})

router.afterEach((to, from) => {
  // sendToAnalytics(to.fullPath)
  menuRecord().SET_RECORD(to)
})


export default router;
